﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using BOHVote.BLL;

namespace BOH.ControlPanel
{
    public partial class GovernModify : System.Web.UI.Page
    {
        protected string pageType = string.Empty;
        protected string ID = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            pageType = Request.QueryString["type"];
            ID = Request.QueryString["ID"];
            if (!IsPostBack)
            {
                if (pageType != null && ID != null && ID.Trim().Length > 0 && pageType == "edit")
                {
                    getGovernbyID(ID);
                }
            }
        }

        protected void getGovernbyID(string ID)
        {
            DataSet dst = UnitClass.getGovernByID(ID);
            this.txtContactPerson.Text = dst.Tables[0].Rows[0]["ContactPerson"].ToString();
            this.txtContactPhone.Text = dst.Tables[0].Rows[0]["ContactPhone"].ToString();
            this.txtGovernID.Text = dst.Tables[0].Rows[0]["GovernID"].ToString();
            this.txtGovernName.Text = dst.Tables[0].Rows[0]["GovernName"].ToString();
            this.txtPostCode.Text = dst.Tables[0].Rows[0]["PostalCode"].ToString();
            this.drpApply.SelectedValue = dst.Tables[0].Rows[0]["ApplyConfirmedInd"].ToString();
            this.drpGovernStatus.SelectedValue = dst.Tables[0].Rows[0]["Status"].ToString();
        }


        protected void butSave_Click(object sender, EventArgs e)
        {
            if (pageType != null && ID != null && ID.Trim().Length > 0 && pageType == "edit")
            {
                UnitClass.UpdateGovern(ID, this.txtGovernID.Text.ToString(), this.txtGovernName.Text.Trim().ToString(), this.txtPostCode.Text.Trim().ToString(), this.txtContactPerson.Text.Trim().ToString(), this.txtContactPhone.Text.Trim().ToString(), this.drpApply.SelectedValue.ToString(), this.drpGovernStatus.SelectedValue.ToString());
            }
            else
            {
                UnitClass.InsertGovern(this.txtGovernID.Text.ToString(), this.txtGovernName.Text.Trim().ToString(), this.txtPostCode.Text.Trim().ToString(), this.txtContactPerson.Text.Trim().ToString(), this.txtContactPhone.Text.Trim().ToString(), this.drpApply.SelectedValue.ToString(), this.drpGovernStatus.SelectedValue.ToString());
            }
        }
    }
}
